package com.copa.l1572;

/**
 * @author copa
 * @createDate 2022-08-31 11:41
 * @function 逐行取数
 */
public class Test1 {

    public int diagonalSum(int[][] mat) {
        if (mat.length == 1) {
            return mat[0][0];
        }
        int result = 0;
        int arrayLength = mat.length;
        for (int i = 0; i < mat.length; i++) {
            result += mat[i][i];
            result += mat[i][arrayLength - i - 1];
        }
        return mat.length % 2 == 0 ? result : result - mat[arrayLength / 2][arrayLength / 2];
    }

    public static void main(String[] args) {
//        int[][] mat = {
//                {1,2,3},
//                {4,5,6},
//                {7,8,9}
//        };
        int[][] mat = {
                {1,1,1,1,1},
                {1,1,1,1,1},
                {1,1,1,1,1},
                {1,1,1,1,1},
                {1,1,1,1,1}
        };
        System.out.println(new Test1().diagonalSum(mat));
    }
}
